package com.nut.spp.baidu;

import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;

import java.util.List;


public class MapUtil {

    /**
     * 行政区划查询
     * https://lbsyun.baidu.com/index.php?title=webapi/district-search
     * 接口url
     * keyword        检索行政区划关键字
     * subAdmin       0：不返回下级行政区；1：返回下一级行政区；2：返回下两级行政区；3：返回下三级行政区；
     * extensionsCode 是否召回国标行政区划编码，1(召回)；0(不召回)
     */
    private static final String URL_REGION = "https://api.map.baidu.com/api_region_search/v1/?ak=pXjri50H9cKlq8PNy530b91h7aA3Ld4F&keyword=中国&sub_admin=3&extensions_code=1";

    public static List<RegionResult.District> allRegion() {
        String response = HttpRequest.get(URL_REGION).execute().body();
        RegionResult bean = JSONUtil.toBean(response, RegionResult.class);

        List<RegionResult.District> districts = bean.getDistricts();

        return districts.get(0).getDistricts();
    }


    public static void main(String[] args) {

//        String response = HttpRequest.get(URL_REGION).execute().body();
//        RegionResult bean = JSONUtil.toBean(response, RegionResult.class);
//
//        List<RegionResult.District> districts = bean.getDistricts();
//
//        System.out.println(bean);

        List<RegionResult.District> list = allRegion();
        System.out.println(list.size());

    }


}
